	<?php
$nbparpage = 10;
    /*
     * recherche
     */

$db = new Mypdo();

    ?>

<form action="#" method="get">
    <fieldset>
        <legend>Recherche</legend>
        <label for="type_loc">Type de location :</label><select name="type_loc" id="type_loc" required="required">
            <option>Selectionner...</option>
            <option <?php if(!empty($_GET['type_loc'])){ echo $_GET['type_loc'] == 'appart'?'selected':''; } ?> value="appart">Appartement</option>
            <option <?php if(!empty($_GET['type_loc'])){ echo $_GET['type_loc'] == 'mais'?'selected':''; } ?> value="mais">Maison</option>
            <option <?php if(!empty($_GET['type_loc'])){ echo $_GET['type_loc'] == 'chamb'?'selected':''; } ?> value=chamb>Chambre</option>

        </select><br/>
        m² : <label for="mmin">min</label>
        <input <?php if(!empty($_GET['mmin'])){ echo 'value="'.$_GET['mmin'].'"';} ?> min="0" id="mmin" name="mmin" type="number"/>
        <label for="mmax">max</label>
        <input <?php if(!empty($_GET['mmax'])){ echo 'value="'.$_GET['mmax'].'"';} ?> min="0" id="mmax" name="mmax" type="number"/>
        <label for="lieu">Localisation</label>
        <input <?php if(!empty($_GET['lieu'])){ echo 'value="'.$_GET['lieu'].'"';} ?> id="lieu" name="lieu" type="text"/>
        <br/>
        Budget : <label for="bmin">min</label>
        <input <?php if(!empty($_GET['bmin'])){ echo 'value="'.$_GET['bmin'].'"';} ?> min="0" id="bmin" name="bmin" type="number"/>
        <label for="bmax">max</label>
        <input <?php if(!empty($_GET['bmax'])){ echo 'value="'.$_GET['bmax'].'"';} ?> min="0" id="bmax" name="bmax" type="number"/>
        <label for="piece">Pièce :</label>
        <input <?php if(!empty($_GET['piece'])){ echo 'value="'.$_GET['piece'].'"';} ?> min="0" id="piece" name="piece" type="number"/>
        <input type="submit" value="Rechercher" />
    </fieldset>
</form>



    <?php
    /*
     * locations
     */

    $locManager = new LocationManager($db);
    $photoManager = new PhotoManager($db);

    if(!isset($_GET['p'])||$_GET['p'] < 1){
        $_GET['p'] = 1;
    }

    if(empty($_GET)){
        $liste = $locManager->getListByPage($_GET['p']);
        $nb = $locManager->getNb();
    }
    else{
        $liste = $locManager->getLocByMultiRecherchePage($_GET);
        $nb = $locManager->getNbByMultiRecherche($_GET);
    }
    ?>
    <table>
    <?php
    foreach ($liste as $value) {
    $photo = $photoManager->getPremierPhotoLoc($value->getIdLoc());
        ?>
        <tr>
            <td>
                <a href="index.php?page=1&id=<?php echo $value->getIdLoc(); ?>">
                    <img class="min" src="image/upload/<?php echo $photo->getLienPhoto() == ''?'default.png':$photo->getLienPhoto(); ?>">
                </a>

            </td>
            <td>
                <a href="index.php?page=1&id=<?php echo $value->getIdLoc(); ?>">
                    <p class="intituler" ><?php echo $value->getNomLoc(); ?></p>
                </a>
                <p>Loyer : <?php echo $value->getMontantLoc().'€'; ?></p>
                <p class="descp"><?php echo $value->getDescpLoc(); ?></p>
            </td>
        </tr>
    <?php
    }

    ?>

    </table>
<?php
//var_dump($_GET);
//var_dump($nb);
if($_GET['p'] > 1){
    ?>
    <form method="get">

        <?php

        foreach($_GET as $key=>$value){
            if($key == 'p'){
               ?> <input type="hidden" id="p" name="p" value="<?php echo $_GET['p']-1 ?>"/> <?php
            }
            else{
           ?> <input type="hidden" id="<?php echo $key; ?>" name="<?php echo $key; ?>" value="<?php echo $value; ?>"/><?php
            }
        }

        ?>


        <input type="submit" id="pagepré" value="Précédent" />
    </form>

<?php
}
if($_GET['p']*$nbparpage<$nb){
    ?>
    <form method="get">
        <?php

        foreach($_GET as $key=>$value){
            if($key == 'p'){
                ?> <input type="hidden" id="p" name="p" value="<?php echo $_GET['p']+1 ?>"/> <?php
            }
            else{
                ?> <input type="hidden" id="<?php echo $key; ?>" name="<?php echo $key; ?>" value="<?php echo $value; ?>"/><?php
            }
        }

        ?>
        <input type="submit" id="pagesui" value="suivant" />
    </form>

<?php
}
?>